package logic

import (
	"context"
	"novel-sys/model/mysql"

	"novel-sys/goods/goods"
	"novel-sys/goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddLogic {
	return &NovelAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NovelAddLogic) NovelAdd(in *goods.NovelAddRequest) (*goods.NovelAddResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Novel{
		Title:    in.Title,
		Category: in.Category,
		Label:    in.Label,
		Info:     in.Info,
		UserId:   in.UserId,
	}

	if err := data.NovelAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &goods.NovelAddResponse{
		NovelId: int64(data.ID),
	}, nil
}
